<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>register - 注册</title>
    <meta name="description" content="">
    <meta name="author" content="templatemo">
    <link href="/favicon.ico" type="image/vnd.microsoft.icon" rel="shortcut icon"/>
    <link href="/static/css/font-awesome.min.css" rel="stylesheet">
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/css/templatemo-style.css" rel="stylesheet">
</head>
<body class="light-gray-bg">
<div class="templatemo-content-widget templatemo-login-widget white-bg tp-8">
    <header class="text-center">
        <div class="square"></div>
        <h1>注册</h1>
    </header>
    <form action="index.html" class="templatemo-login-form">
        <div class="form-group">
            <div class="input-group">
                <div class="input-group-addon"></div>
                <input type="text" id="username" name="username" class="form-control" placeholder="用户名">
            </div>
        </div>
        <div class="form-group">
            <div class="input-group">
                <div class="input-group-addon"></div>
                <input type="password" id="password" name="password" class="form-control" placeholder="密码">
            </div>
        </div>
        <div class="form-group">
            <div class="input-group">
                <div class="input-group-addon"></div>
                <input type="password" id="confirmpassword" name="confirmpassword" class="form-control" placeholder="确认密码">
            </div>
        </div>
        <div class="form-group">
            <button type="button" class="templatemo-blue-button width-100 login_btn">登陆</button><br><br>
            <a href="{:url('chat/User/login')}" class="blue-text" style="color: #3F3F3F;cursor:pointer ">已有账号？直接登录</a>
        </div>
    </form>
</div>
<!--<div class="templatemo-content-widget templatemo-login-widget templatemo-register-widget white-bg">-->
<!--    <p><strong><a href="{:url('chat/User/register')}" class="blue-text">注册</a></strong></p>-->
<!--</div>-->
<script type="text/javascript" src="/static/layui/dist/layui.js"></script>

<script>
    layui.use(['layer', 'jquery'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        $(function () {
            document.onkeyup = function (e) {
                var ev = document.all ? window.event : e;
                if (ev.keyCode === 13) {
                    $('.login_btn').click();
                }
            };
        });

        $('.login_btn').click(function () {
            var name = $('#username').val();
            var pwd = $('#password').val();
            var pwd1 = $('#confirmpassword').val();
            if (name == '' || $.trim(name).length == 0) {
                layer.tips('请输入登录名称', '#username', {tips: [3, '#3595cc'], anim: 4});
                return false;
            }
            if (pwd == '' || $.trim(pwd).length == 0) {
                layer.tips('请输入登录密码', '#password', {tips: [3, '#3595cc'], anim: 4});
                return false;
            }
            if (pwd  != pwd1) {
                layer.tips('两次密码不一样', '#confirmpassword', {tips: [3, '#3595cc'], anim: 4});
                return false;
            }

            var url = "{:url('chat/User/register')}";
            $.ajax({
                type: "POST",
                url: url,
                data: {name: name, pwd: pwd,pwd1:pwd1},
                dataType: "json",
                beforeSend: function () {
                    layer.load(0, {shade: 0.1});
                },
                success: function (res) {
                    layer.closeAll('loading');
                    if (res.state != 'error') {
                        layer.msg(res.msg, {icon: 1});
                        var url = "{:url('chat/user/login')}";
                        setTimeout(window.location.href = url, 3000);
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }
            });
        });
    });
</script>
</body>
</html>